package com.ciko.code.fragment;


import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;

import com.ciko.code.adapter.WorkHotActionListAdapter;
import com.ciko.code.base.BaseFragment;
import com.ciko.code.bean.GetHotActivitiesListEty;
import com.ciko.code.http.BaseResponse;
import com.ciko.code.http.HttpClient;
import com.ciko.code.http.Req.GetHotActivitiesListReq;
import com.ciko.code.views.PullListView;
import com.mywork.R;
import com.mywork.activity.WebActivity;
import com.mywork.activity.WorkActionActivity;
import com.mywork.activity.WorkManagerActivity;
import com.mywork.activity.WorkMeetingActivity;
import com.mywork.activity.WorkOfficeActivity;
import com.mywork.activity.WorkPlaneActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 12154 on 2015/10/29.
 */
public class WorkFragment extends BaseFragment implements AdapterView.OnItemClickListener{

    private View rect_managerWork;
    private View rect_actionWork;
    private View rect_planeWork;
    private View rect_officWork;
    private View rect_meetingWork;

    private PullListView lv_hotActionWork;

    private WorkHotActionListAdapter workHotActionListAdapter;
    private List<GetHotActivitiesListEty> getHotActivitiesListEtyList = new ArrayList<>();

    @Override
    protected void initTopBar() {
        unableNav();
    }

    @Override
    protected void initLayout() {
        setContentView(R.layout.fragment_work);
    }

    @Override
    protected void initView() {
        rect_managerWork = findViewById(R.id.rect_managerWork);
        rect_actionWork = findViewById(R.id.rect_actionWork);
        rect_planeWork = findViewById(R.id.rect_planeWork);
        rect_officWork = findViewById(R.id.rect_officWork);
        rect_meetingWork = findViewById(R.id.rect_meetingWork);

        lv_hotActionWork = findViewById(R.id.lv_hotActionWork);
    }

    @Override
    protected void initAdapter() {

        workHotActionListAdapter = new WorkHotActionListAdapter(getContext(), getHotActivitiesListEtyList, R.layout.item_list_work_hot_action);

        lv_hotActionWork.setAdapter(workHotActionListAdapter);
    }

    @Override
    protected void initDates() {

    }

    @Override
    protected void initHttpRequest() {
        HttpClient.getInstance(getContext()).post(new GetHotActivitiesListReq(0 ,10), this);
    }

    @Override
    protected void initListener() {
        rect_managerWork.setOnClickListener(this);
        rect_actionWork.setOnClickListener(this);
        rect_planeWork.setOnClickListener(this);
        rect_officWork.setOnClickListener(this);
        rect_meetingWork.setOnClickListener(this);

        lv_hotActionWork.setOnItemClickListener(this);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if(v==rect_managerWork){
            intent2Acticity(WorkManagerActivity.class);
        } else if(v==rect_actionWork){
            intent2Acticity(WorkActionActivity.class);
        } else if(v==rect_planeWork){
            intent2Acticity(WorkPlaneActivity.class);
        } else if(v==rect_officWork){
            intent2Acticity(WorkOfficeActivity.class);
        } else if(v==rect_meetingWork){
            intent2Acticity(WorkMeetingActivity.class);
        }

//
//        switch (v.getId()) {
//            case R.id.rect_managerWork:
//                intent2Acticity(WorkManagerActivity.class);
//                break;
//            case R.id.rect_actionWork:
//                intent2Acticity(WorkActionActivity.class);
//                break;
//            case R.id.rect_planeWork:
//                intent2Acticity(WorkPlaneActivity.class);
//                break;
//            case R.id.rect_officWork:
//                intent2Acticity(WorkOfficeActivity.class);
//                break;
//            case R.id.rect_meetingWork:
//                intent2Acticity(WorkMeetingActivity.class);
//                break;
//        }

    }

    @Override
    public void onResponseSuccess(BaseResponse<?> response, String tag) {
        super.onResponseSuccess(response, tag);

        switch (tag) {
            case "GetHotActivitiesListReq":

                List<GetHotActivitiesListEty> getHotActivitiesListEtyListResult = (List<GetHotActivitiesListEty>) response.getReturnObject();

                getHotActivitiesListEtyList.addAll(getHotActivitiesListEtyListResult);
                workHotActionListAdapter.notifyDataSetChanged();

                break;

        }
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

        GetHotActivitiesListEty getHotActivitiesListEty = (GetHotActivitiesListEty) parent.getAdapter().getItem(position);


        if(getHotActivitiesListEty.getHasHtml().equals("y")) {
            Intent intent = new Intent(getActivity(), WebActivity.class);
            intent.putExtra("URL", getHotActivitiesListEty.getHtmlUrl());
            getContext().startActivity(intent);
        }

    }
}
